-- split_spell_attrib
-- Created by shuzy
-- 分解卷轴提升属性

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 触发
    trigger = function(who, prop, count)
        local bonusList = string.explode(prop[2], "~");
        for _, bonusStr in pairs(bonusList) do
            local arr = string.explode(bonusStr, "+");
            if #arr > 1 then
                arr[2] = tonumber(arr[2]);

                BonusM.doBonus({2, arr[1], arr[2] * count,}, "prop split_spell_attrib")

                -- 奖励飘字
                doAlert(string.format(getLocStr("attrib_bonus_format"), FieldsM.getFieldName(arr[1]), arr[2] * count), 1);
                -- 奖励事件
                EventMgr.fire(event.SKILL_BONUS, { ["bonus"] = {2, arr[1], arr[2] * count,}});
            end
        end
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        desc = string.gsub(desc, "{1}", prop[3]);

        local bonusList = string.explode(prop[2], "~");

        -- 属性描述，暂时只管1、2个的情况
        if #bonusList == 1 then
            local bonusStr = bonusList[1];
            local arr = string.explode(bonusStr, "+");
            if #arr > 1 then
                arr[2] = tonumber(arr[2]);
                desc = string.gsub(desc, "{0}", FieldsM.getFieldName(arr[1]));
                desc = string.gsub(desc, "{2}", arr[2]);
            end
        elseif #bonusList == 2 then
            local attribName;
            local bonusStr = bonusList[1];
            local arr = string.explode(bonusStr, "+");
            if #arr > 1 then
                attribName = FieldsM.getFieldName(arr[1]);
            end
            bonusStr = bonusList[2];
            arr = string.explode(bonusStr, "+");
            if #arr > 1 then
                attribName = attribName .. getLocStr("and2") .. FieldsM.getFieldName(arr[1]);
            end
            desc = string.gsub(desc, "{0}", attribName);
            desc = string.gsub(desc, "{2}", arr[2]);
        end

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end,
};